package com.huatai.bi.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.bi.entity.PythonTemplateEntity;
import com.huatai.bi.service.PythonTemplateIService;
import com.huatai.common.api.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description python模板的控制器
 * @author zcw
 * @createTime 2024-6-19 15:00
 */
@RestController
@RequestMapping("/pythonTemplate")
@Api(value = "python模板管理", tags = "python模板管理")
public class PythonTemplateController {

    @Autowired
    private PythonTemplateIService service;

    @PostMapping("/savePythonTemplate")
    @ApiOperation(value = "新增python模板", notes = "新增python模板")
    @ApiOperationSupport(order = 1)
    public R<Boolean> savePythonTemplate(@RequestBody PythonTemplateEntity entity){
        service.savePythonTemplate(entity);
        return R.data(null);
    }

    @GetMapping("/get/{id}")
    @ApiOperation(value = "获取python模板信息", notes = "获取python模板信息")
    @ApiOperationSupport(order = 2)
    public R<PythonTemplateEntity> get(@PathVariable("id") Long id){
        return R.data(service.get(id));
    }

    @GetMapping("/listPythonTemplate")
    @ApiOperation(value = "获取所有python模板信息", notes = "获取所有python模板信息")
    @ApiOperationSupport(order = 3)
    public R<List<PythonTemplateEntity>> listPythonTemplate(){
        return R.data(service.listPythonTemplate());
    }

    @PostMapping("/removePythonTemplate/{id}")
    @ApiOperation(value = "删除python模板信息", notes = "删除python模板信息")
    @ApiOperationSupport(order = 4)
    public R<Boolean> removePythonTemplate(@PathVariable Long id){
        return R.data(service.removePythonTemplate(id));
    }

    @GetMapping("/initContent/{id}/{dsId}")
    @ApiOperation(value = "根据数据源ID初始化模板", notes = "根据数据源ID初始化模板")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "模板ID", dataType = "Long"),
            @ApiImplicitParam(name = "dsId", value = "数据源ID", dataType = "Long")
    })
    @ApiOperationSupport(order = 2)
    public R<String> initContent(@PathVariable("id") Long id,@PathVariable("dsId") Long dsId){
        return R.data(service.initContent(id,dsId));
    }
}
